<?php
    // array for JSON response
    $response = array();
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
    // connecting to db
    $db = new DB_CONNECT();
    // get newest place from place table
    $result = mysql_query('SELECT place_id, place_name, url_image FROM place ORDER BY date_create DESC LIMIT 3') or die(mysql_error());
    if (mysql_num_rows($result) > 0) {
            $response["place"] = array();
            while ($row = mysql_fetch_array($result)) {
                    $place = array(); 
                    $place['place_id'] = $row['place_id'];
                    $place['place_name'] = $row['place_name'];
                    $place['url_image'] = $row['url_image'];
                    // push single product into final response array
                    array_push($response['place'],$place);
            }
            // success
        $response["success"] = 1;
            echo json_encode($response);
    }
    else{
        $response["place"] = "No place";
        $response["success"] = 0;
            echo json_encode($response);
    }
?>
